home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6342 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  41 lines

  1. Path: sun001.spd.dsccc.com!spd!jmccarty
  2. From: jmccarty@spd.dsccc.com (Mike McCarty)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: merge algorithm
  5. Date: 23 Feb 1996 23:50:13 GMT
  6. Organization: DSC Communications Corporation, Plano, Texas USA
  7. Message-ID: <4gljrl$auj@sun001.spd.dsccc.com>
  8. References: <312CEE69.842@onyx.idbsu.edu>
  9. NNTP-Posting-Host: aplo139.spd.dsccc.com
  10.  
  11. In article <312CEE69.842@onyx.idbsu.edu>,
  12. Joe E. Coffland <jcofflan@onyx.idbsu.edu> wrote:
  13. )I am trying to find an algorithm to merge two sorted arrays containing
  14. )n elements.
  15. )ie. A[1] <= A[2]<= ... <= A[m] and A[m+1] <= A[m+2] <= ... <A[n]
  16. )The algorithm must run in O(n) time and require only a small amount of
  17. )fixed additional memory regardless of the size of m or n. I have reason
  18. )to believe that there is such an algorithm but I have only been able to
  19. )find algorithms that meet the memory restriction but run in at best
  20. )O(nlogn) and are recursive (which can through some work of course be
  21. )changed in to an iterative algorithm). If any one can point me to a book
  22. )or any other source of information on the subject or just get me headed
  23. )in the right direction it would be greatly appriciated.
  24. )
  25. )Thank you in advance,
  26. )Joe Coffland
  27. )please mail to: jcofflan@onyx.idbsu.edu
  28.  
  29.  
  30. Won't a simple exchange algorithm work? Start with pointers into the
  31. left and right halves. Advance the left pointer until you find an
  32. element larger than the right pointer data. Exchange the left pointer
  33. data with the right pointer data. Advance the left pointer etc. When you
  34. have gone through the entire data set, there is only one output array.
  35.  
  36. Mike
  37. ----
  38. char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
  39.  
  40. I don't speak for DSC.         <- They make me say that.
  41.